package cn.tedu.egaddress0805.controller;

import cn.tedu.egaddress0805.mapper.AddressMapper;
import cn.tedu.egaddress0805.pojo.dto.AddressAddParam;
import cn.tedu.egaddress0805.pojo.vo.AddressInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/address/")
public class AddressController {
    @Autowired
    private AddressMapper addressMapper;

    @PostMapping("add")
    public String addAddress(@RequestBody AddressAddParam addressAddParam){
        addressMapper.addAddress(addressAddParam);
        return "添加地址成功";
    }

    @GetMapping("list")
    public List<AddressInfoVO> listAddress(){
        List<AddressInfoVO> list = addressMapper.selectAddressAll();
        return list;
    }

    @PostMapping("del/{addressId}")
    public String delAddressById(@PathVariable("addressId") Integer id){
        addressMapper.deleteAddressById(id);
        return "删除成功";
    }
}
